import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class BatchSql{
    public static void main(String[] args){
        
        try{
            //装载Driver类
            Class.forName("com.mysql.jdbc.Driver");
            
            //连接数据库
            String url = "jdbc:mysql://localhost:3306/test?useSSL=false";
            String username = "root";
            String password = "";
            Connection conn = DriverManager.getConnection(url, username, password);
            
            //获取Statement
            Statement stmt = conn.createStatement();    
            
            /**************** 批量提交 *********************/
            
            String sql1 = "insert into user (username, psw) values ('fuck', 'you')";
            String sql2 = "update user set psw = 'heihei' where id = 7";
            String sql3 = "delete from user where id = 1";
            
            //装入缓冲区（Batch容器）
            stmt.addBatch(sql1);
            stmt.addBatch(sql2);
            stmt.addBatch(sql3);
            
            //执行容器中所有的SQL语句
            stmt.executeBatch();
            
            stmt.close();
            conn.close();
        }catch(Exception e){
            e.printStackTrace();
        }
        
    }
}